<?php 
class Users extends E_Entity 
{
	public   $table =array(
					"id" =>"id",
					"version"=>"version",
					"iid"=>"iid",
					"email"=>"email",
					"sign" =>"sign",
					"status" =>"status",
					"ctime" =>"ctime",
					"mtime" =>"mtime"
					);
					
	public function getTableName()
	{
		return "micro_user";
	}
	public function getJoinMap()
	{
		$map = array("mapSite" =>array("Entity"=>"Sites","Method"=>"getByUserid", "param"=>"id"),
		
		);
		return $map;
	}
	public static function insertEntity($row)
	{	
		$entity = new self();
	 	return $entity->createEntityForRow($row);
	}
	public static function getById($id)
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where  {$entity->table['id']} = :id";
		return $entity->getEntityByIndexKey($sql, $id, array("id"=>$id));
	}
	public static function getByIid($iid)
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where  {$entity->table['iid']} = :iid";
		return $entity->getEntityByIndexKey($sql, $id, array("iid"=>$iid));
	}
	public static function getByUid($uid)
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where  {$entity->table['uid']} = :uid";
		return $entity->getEntityByIndexKey($sql, $id, array("uid"=>$uid));
	}
	public static function getByEmail($email)
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where  {$entity->table['email']} = :email";
		return $entity->getEntityByIndexKey($sql, $id, array("email"=>$email));
	}
	public  function getUid()
	{
		if($this->sign == 1)
		{
			$suser_E = Susers::getById($this->iid);
			return $suser_E->uid;
		}
		else if($this->sign == 2)
		{
			$quser_E = Qusers::getById($this->iid);
			return $quser_E->uid;
		}
	}
	public function getIcon()
	{
		if($this->sign == 1)
		{
			return '/pics/tsina_icon.png';
		}
		else if($this->sign == 2)
		{
			return '/pics/tqq_icon.png';
		}
		
	}
	public  function getHref()
	{
		if($this->sign == 1)
		{
			$suser_E = Susers::getById($this->iid);
			$href = "http://t.sina.com.cn/".$suser_E->uid;
			return $href;
		}
		else if($this->sign == 2)
		{
			$quser_E = Qusers::getById($this->iid);
			$href = "http://t.qq.com/".$quser_E->uid;
			return $href;
		}
	}
	public  function getName()
	{
		if($this->sign == 1)
		{
			$suser_E = Susers::getById($this->iid);
			return $suser_E->name;
		}
		else if($this->sign == 2)
		{
			$quser_E = Qusers::getById($this->iid);
			return $quser_E->name;
		}
	}
	public  function getImage()
	{
		if($this->sign == 1)
		{
			$suser_E = Susers::getById($this->iid);
			return $suser_E->profile_image_url;
		}
		else if($this->sign == 2)
		{
			$quser_E = Qusers::getById($this->iid);
			$head = $quser_E->head;
			if(empty($head))
			{
				$head = "/pics/site/head_50.jpg";
			}
			return $head;
		}
	}
}
?>